/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.pitkley.jocabulary;

import java.util.Random;

/**
 *
 * @author pit
 */
public class Vocable {

    private Unit parentUnit = null;
    private static final Random r = new Random();
    private boolean required;
    private String type = null;
    private String[] nativeWords = null;
    private String[] translations = null;
    private int timesCorrect;

    public Vocable(Unit pUnit) {
        parentUnit = pUnit;
    }

    public void setRequired(boolean pRequired) {
        required = pRequired;
    }

    public boolean getRequired() {
        return required;
    }

    public void setType(String pType) {
        type = pType;
    }

    public String getType() {
        return type;
    }

    public void setNativeWords(String[] pNativeWords) {
        nativeWords = pNativeWords;
    }

    public String[] getNativeWords() {
        return nativeWords;
    }

    public String getRandomNativeWord() {
        return nativeWords[r.nextInt(nativeWords.length)];
    }

    public boolean verifyNativeWord(String pNativeWord) {
        for (String s : nativeWords) {
            if (s.equalsIgnoreCase(pNativeWord)) {
                return true;
            }
        }
        return false;
    }

    public void setTranslations(String[] pTranslations) {
        translations = pTranslations;
    }

    public String[] getTranslations() {
        return translations;
    }

    public String getRandomTranslation() {
        return translations[r.nextInt(translations.length)];
    }

    public boolean verifyTranslation(String pTranslation) {
        for (String s : translations) {
            if (s.equalsIgnoreCase(pTranslation)) {
                return true;
            }
        }
        return false;
    }

    public int getTimesCorrect() {
        return timesCorrect;
    }

    public void setTimesCorrect(int pTimesCorrect) {
        timesCorrect = pTimesCorrect;
    }

    public void answer(boolean correct) {
        if (correct) {
            timesCorrect++;
        } else {
            timesCorrect = 0;
        }
    }
}
